import { message } from 'ant-design-vue'

import manualMessage from '@/components/ManualMessage/index'
import { clientApi, fetchDownload } from '@/services/api'

/* 下载指纹文件 */
export const downloadFingerprint = async (fileId: string) => {
  manualMessage.loading('数据准备中,请耐心等待...', 0)
  try {
    const { data } = await clientApi.downloadFingerprint({}, { urlParams: { id: fileId } })
    await fetchDownload(data.fileUrl, `${data.fileName}`)
    manualMessage.destroy()
    await message.success({ content: '文件下载成功', key: 'downloading', duration: 2 })
  } catch (error) {
    message.error({ content: '文件下载失败', key: 'downloading', duration: 2 })
  }
}
